<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>购物车</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
	function jian(pid,uid,count) {
		if (count==1){
			location.href = "cart?method=deleteCart&pid=" + pid ;
		}else {
			location.href = "cart?method=subtractCart&pid=" + pid + "&count=" +count;
		}
	}
	function jia(pid,uid,count) {

		location.href = "cart?method=addCartCount&pid=" + pid + "&count=" +count;

	}
	function shanchu(pid) {

		location.href = "cart?method=deleteCart&pid=" + pid ;

	}
	function qingkong(uid) {
		//alert(uid);
		location.href = "cart?method=clearCart";
	}
	// function getSum() {
	// 	var price_total = 0;
	// 	$(".sum0").each(function(index,el){
	// 		var price_tmp = price_total+parseFloat($(el).text().substr(1));
	// 		price_total = price_tmp;
	// 		console.log(price_total);
	// 	})
	// 	$("#total").text("￥"+price_total.toFixed(2))
	// }
</script>
</head>
<body style="background-color:#f5f5f5">
<%@ include file="header.jsp"%>
<div class="container" style="background-color: white;">
	<div class="row" style="margin-left: 40px">
		<h3>我的购物车<small>温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</small></h3>
	</div>
	<div class="row" style="margin-top: 40px;">
		<div class="col-md-10 col-md-offset-1">
			<table class="table table-bordered table-striped table-hover">
 				<tr>
 					<th>序号</th>
 					<th>商品名称</th>
 					<th>价格</th>
 					<th>数量</th>
 					<th>小计</th>
 					<th>操作</th>
 				</tr>
 				<c:set value="0" var="sum"></c:set>
 				<c:forEach items="${cartList}" var="c" varStatus="i">
	 				<tr>
	 					<th>${c.count}</th>
	 					<th>${c.pname}</th>
	 					<th>${c.pprice}</th>
<%--						<th style="display: none" id="pid">${c.pid}</th>--%>
	 					<th width="100px">
		 					<div class="input-group">
		 						<span class="input-group-btn">
		 							<button id="jian" class="btn btn-default" type="button" onclick="jian(${c.pid},${c.uid},${c.count})">-</button>
		 						</span>
		 						<input type="text" class="form-control"  id="count" value="${c.count}"  readonly="readonly" style="width:40px">
		 						<span class="input-group-btn">
		 							<button id="jia" class="btn btn-default" type="button" onclick="jia(${c.pid},${c.uid},${c.count})">+</button>
		 						</span>
	 						</div>
	 					</th>
	 					<th class="sum0">¥${c.count*c.pprice}</th>
	 					<th>
	 						<button type="button" class="btn btn-default" onclick="shanchu(${c.pid})">删除</button>
	 					</th>
	 				</tr>
	 				<c:set var="sum" value="${sum+c.count*c.pprice}"></c:set>
 				</c:forEach>
			</table>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="pull-right" style="margin-right: 40px;">
	            <div>
	            	<a id="removeAllProduct"  class="btn btn-default btn-lg" onclick="qingkong()">清空购物车</a>
	            	&nbsp;&nbsp;
	            	<a href="${pageContext.request.contextPath}/cart?method=jumpCart" class="btn  btn-danger btn-lg">添加收货地址</a>
	            </div>
	            <br><br>
	            <div style="margin-bottom: 20px;">        		  
	            	商品金额总计：<span id="total" class="text-danger"><b id="sb">￥&nbsp;&nbsp;${sum}</b></span>
	            </div>
		</div>
	</div>
</div>
<!-- 底部 -->
<%@ include file="footer.jsp"%>
</body>
</html>